USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Persons-Insert]    Script Date: [[20120914064959]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064959]]
-- Description:	Insert record into table [dbo].[Persons]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Persons-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Persons-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Persons-Insert]
	/*@Person_RowNumber int =Null OUTPUT , 
	@Person_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Person_Code varchar(50) =Null  , 
	@Person_NameAr varchar(300) =Null  , 
	@Person_NameEn varchar(300) =Null  , 
	@Person_Notes varchar(max) =Null  , 
	@Person_Search varchar(max) =Null  , 
	@Person_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Persons](/*[Person_ID], [Dealer_ID], [Person_Code], [Person_NameAr], [Person_NameEn], [Person_Notes], [Person_Search]*/)
	VALUES     (/*@Person_ID, @Dealer_ID, @Person_Code, @Person_NameAr, @Person_NameEn, @Person_Notes, @Person_Search*/)

	/*SELECT @Person_RowNumber = [Person_RowNumber], @Person_TimeStamp = [Person_TimeStamp]
    FROM [dbo].[Persons]
    WHERE  ( [Person_ID] =@Person_ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Person_Code] =@Person_Code )
	AND  ( [Person_NameAr] =@Person_NameAr )
	AND  ( [Person_NameEn] =@Person_NameEn )
	AND  ( [Person_Notes] =@Person_Notes )
	AND  ( [Person_Search] =@Person_Search )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Persons-update]    Script Date: [[20120914064959]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064959]]
-- Description:	Update record in table [dbo].[Persons]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Persons-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Persons-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Persons-update]
	/*@Person_RowNumber int =Null OUTPUT , 
	@Person_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Person_Code varchar(50) =Null  , 
	@Person_NameAr varchar(300) =Null  , 
	@Person_NameEn varchar(300) =Null  , 
	@Person_Notes varchar(max) =Null  , 
	@Person_Search varchar(max) =Null  , 
	@Person_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Person_TimeStamp]
    FROM [dbo].[Persons]
    	WHERE ([Person_ID] = @Person_ID)

    IF  @OldTimeStamp = @Person_TimeStamp
    BEGIN*/
		Update [dbo].[Persons] SET 
		/*[Person_ID] =@Person_ID, 
		[Dealer_ID] =@Dealer_ID, 
		[Person_Code] =@Person_Code, 
		[Person_NameAr] =@Person_NameAr, 
		[Person_NameEn] =@Person_NameEn, 
		[Person_Notes] =@Person_Notes, 
		[Person_Search] =@Person_Search*/
		/*WHERE ([Person_ID] = @Person_ID)*/
	/*END*/

	/*SELECT @Person_RowNumber = [Person_RowNumber], @Person_TimeStamp = [Person_TimeStamp]
    FROM [dbo].[Persons]
	WHERE ([Person_ID] = @Person_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Persons-Insert-Update]    Script Date: [[20120914064959]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064959]]
-- Description:	Insert OR Update record into table [dbo].[Persons]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Persons-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Persons-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Persons-Insert-Update]
	/*@Person_RowNumber int =Null OUTPUT , 
	@Person_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Person_Code varchar(50) =Null  , 
	@Person_NameAr varchar(300) =Null  , 
	@Person_NameEn varchar(300) =Null  , 
	@Person_Notes varchar(max) =Null  , 
	@Person_Search varchar(max) =Null  , 
	@Person_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Persons] 
					/*WHERE ([Person_ID] = @Person_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Persons](/*[Person_ID], [Dealer_ID], [Person_Code], [Person_NameAr], [Person_NameEn], [Person_Notes], [Person_Search]*/)
		VALUES     (/*@Person_ID, @Dealer_ID, @Person_Code, @Person_NameAr, @Person_NameEn, @Person_Notes, @Person_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Person_TimeStamp]
		FROM [dbo].[Persons]
    	WHERE ([Person_ID] = @Person_ID)

		IF  @OldTimeStamp = @Person_TimeStamp
		BEGIN*/
			Update [dbo].[Persons] SET 
			/*[Person_ID] =@Person_ID, 
			[Dealer_ID] =@Dealer_ID, 
			[Person_Code] =@Person_Code, 
			[Person_NameAr] =@Person_NameAr, 
			[Person_NameEn] =@Person_NameEn, 
			[Person_Notes] =@Person_Notes, 
			[Person_Search] =@Person_Search*/
			/*WHERE ([Person_ID] = @Person_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Person_RowNumber = [Person_RowNumber], @Person_TimeStamp = [Person_TimeStamp]
    FROM [dbo].[Persons]
	WHERE ([Person_ID] = @Person_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Persons-Delete]    Script Date: [[20120914064959]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064959]]
-- Description:	delete records from table [dbo].[Persons] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Persons-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Persons-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Persons-Delete]
	/*@Person_RowNumber int =null  , 
	@Person_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Person_Code varchar(50) =null  , 
	@Person_NameAr varchar(300) =null  , 
	@Person_NameEn varchar(300) =null  , 
	@Person_Notes varchar(max) =null  , 
	@Person_Search varchar(max) =null  , 
	@Person_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Persons]
	WHERE /*( [Person_RowNumber] = ISNULL(@Person_RowNumber, [Person_RowNumber]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Person_Code] like ISNULL(@Person_Code, [Person_Code]) )
	AND ( [Person_NameAr] like ISNULL(@Person_NameAr, [Person_NameAr]) )
	AND ( [Person_NameEn] like ISNULL(@Person_NameEn, [Person_NameEn]) )
	AND ( [Person_Notes] like ISNULL(@Person_Notes, [Person_Notes]) )
	AND ( [Person_Search] like ISNULL(@Person_Search, [Person_Search]) )
	AND ( [Person_TimeStamp] = ISNULL(@Person_TimeStamp, [Person_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Persons-Select]    Script Date: [[20120914064959]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064959]]
-- Description:	select records from table [dbo].[Persons] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Persons-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Persons-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Persons-Select]
	/*@Person_RowNumber int =null  , 
	@Person_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Person_Code varchar(50) =null  , 
	@Person_NameAr varchar(300) =null  , 
	@Person_NameEn varchar(300) =null  , 
	@Person_Notes varchar(max) =null  , 
	@Person_Search varchar(max) =null  , 
	@Person_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Persons]
	WHERE /*( [Person_RowNumber] = ISNULL(@Person_RowNumber, [Person_RowNumber]) )
	AND ( [Person_ID] = ISNULL(@Person_ID, [Person_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Person_Code] like ISNULL(@Person_Code, [Person_Code]) )
	AND ( [Person_NameAr] like ISNULL(@Person_NameAr, [Person_NameAr]) )
	AND ( [Person_NameEn] like ISNULL(@Person_NameEn, [Person_NameEn]) )
	AND ( [Person_Notes] like ISNULL(@Person_Notes, [Person_Notes]) )
	AND ( [Person_Search] like ISNULL(@Person_Search, [Person_Search]) )
	AND ( [Person_TimeStamp] = ISNULL(@Person_TimeStamp, [Person_TimeStamp]) )*/
END
GO
-- =============================================
